package com.sywb.chuangyebao.view.dialog;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sywb.chuangyebao.R;

import java.io.Serializable;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

public class BindMobiletDialog extends BaseDialogFragment {

    private OnItemListener onItemListener;

    public static BindMobiletDialog newInstance(Object... pramars) {
        BindMobiletDialog dialogFragment = new BindMobiletDialog();
        Bundle bundle = new Bundle();
        if (pramars != null && pramars.length > 0) {
            for (int i = 0; i < pramars.length; i++) {
                bundle.putSerializable("p" + i, (Serializable) pramars[i]);
            }
        }
        dialogFragment.setArguments(bundle);
        return dialogFragment;
    }

    @Override
    public int getLayoutId(Bundle bundle) {
        return R.layout.dialog_bind_mobile;
    }

    @Override
    public void initView(View view, Bundle bundle) {
        getDialog().getWindow().setGravity(Gravity.CENTER);
        getDialog().setCancelable(false);
        getDialog().setCanceledOnTouchOutside(false);
        getDialog().setOnKeyListener(new DialogInterface.OnKeyListener() {
            @Override
            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_BACK) {
                    return true;
                }
                return false;
            }
        });
    }

    @OnClick({R.id.dialog_button_left, R.id.dialog_button_right})
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.dialog_button_right:
                if (onItemListener != null) {
                    onItemListener.onResult(getActivity());
                }
                break;
        }
        exit();
    }

    @Override
    public void onResume() {
        super.onResume();
        // setWindowHeight();
    }

    private void setWindowHeight() {
        WindowManager.LayoutParams p = getDialog().getWindow().getAttributes();
        p.width = RelativeLayout.LayoutParams.MATCH_PARENT;
        p.height = RelativeLayout.LayoutParams.WRAP_CONTENT;
        getDialog().getWindow().setAttributes(p);
    }

    public interface OnItemListener {
        void onResult(Activity activity);
    }

    public void setOnItemListener(OnItemListener onItemListener) {
        this.onItemListener = onItemListener;
    }
}
